/**
 * This file is part of the dspace-poltman project http://www.poltman.com.
 *
 * This is free software; you can redistribute it and/or modify it under
 * the terms of DuraSpace DSpace license detailed in the LICENSE and NOTICE 
 * files at the root of the source tree and available online at
 * http://www.dspace.org/license/
 * 
 */
package com.poltman.dscentral.db.repository.pm;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.poltman.dscentral.db.entity.pm.MainMenuGroupsEntity;


/**
 * 
 * @author Zbigniew Ciok; z.ciok@poltman.com
 * @version $Revision: 1768 $
 *
 */
@Transactional(readOnly = true)
public interface MainMenuGroupsRepository extends JpaRepository<MainMenuGroupsEntity, Integer> {
	
	public List<MainMenuGroupsEntity> findByShortcut(String shortcut);
	
	@Query("select DISTINCT c.shortcut from MainMenuGroupsEntity c order by c.shortcut")
	public List<String> findAllShortcuts();
	
	@SuppressWarnings("unchecked")
	@Modifying
	@Transactional
	public MainMenuGroupsEntity save(MainMenuGroupsEntity mainMenuGroupsEntity);
	
	@Modifying
	@Transactional
	@Query("delete from MainMenuGroupsEntity c where c.shortcut = ?1")
	public void deleteGroupByShortcut(String shortcut);	
	
	@Query("select distinct mmg.menuItem " + 
		   "from MainMenuGroupsEntity mmg, EPersonMenuGroupsEntity umg " +
		   "where mmg.shortcut = umg.groupShortcut and umg.epersonId = ?1 " +
		   "order by mmg.menuItem")
	public List<String> findEPersonMenuItems(Integer epersonId);
}
